package com.lee.lease.web.app.controller.apartment;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lee.lease.common.result.Result;
import com.lee.lease.model.entity.CityInfo;
import com.lee.lease.model.entity.DistrictInfo;
import com.lee.lease.model.entity.ProvinceInfo;
import com.lee.lease.web.app.service.CityInfoService;
import com.lee.lease.web.app.service.DistrictInfoService;
import com.lee.lease.web.app.service.ProvinceInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ClassName: ProvinceController
 * Package: com.lee.lease.web.app.controller.apartment
 * Description:
 */
@Tag(name = "地区信息")
@RestController
@RequestMapping("/app/region/province")
public class ProvinceController {
    @Autowired
    private ProvinceInfoService provinceInfoService;
    @Autowired
    private CityInfoService cityInfoService;
    @Autowired
    private DistrictInfoService districtInfoService;
    @Operation(summary = "查询省份信息列表")
    @GetMapping("list")
    public Result<List<ProvinceInfo>> listProvince(){
        List<ProvinceInfo> list = provinceInfoService.list();
        return Result.ok(list);
    }

    @Operation(summary = "根据省份id查询城市信息列表")
    @GetMapping("/listByProvinceId")
    public Result<List<CityInfo>> listByProvinceId(Integer id){
        LambdaQueryWrapper<CityInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CityInfo::getProvinceId,id);
        List<CityInfo> list = cityInfoService.list(queryWrapper);
        return Result.ok(list);
    }

    @Operation(summary = "根据城市id查询区县信息")
    @GetMapping("/listByCityId")
    public Result<List<DistrictInfo>> listByCityId(Integer id){
        LambdaQueryWrapper<DistrictInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DistrictInfo::getCityId,id);
        List<DistrictInfo> list = districtInfoService.list(queryWrapper);
        return Result.ok(list);
    }
}
